home *** CD-ROM | disk | FTP | other *** search
/ IRIX Base Documentation 2001 May / SGI IRIX Base Documentation 2001 May.iso / usr / share / catman / p_man / cat3 / c++ / demangle.z / demangle
Encoding:
Text File  |  1998-10-30  |  13.9 KB  |  331 lines

  1.  
  2.  
  3.  
  4. ddddeeeemmmmaaaannnngggglllleeee((((3333CCCC++++++++))))                                                  ddddeeeemmmmaaaannnngggglllleeee((((3333CCCC++++++++))))
  5.  
  6.  
  7.  
  8. NNNNAAAAMMMMEEEE
  9.      dem, demangle - demangle C++ external names to a readable format
  10.  
  11. SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
  12.      _####_iiii_nnnn_cccc_llll_uuuu_dddd_eeee _<<<<_dddd_eeee_mmmm_...._hhhh_>>>>
  13.  
  14.      _cccc_cccc _[[[[_f_l_a_g ..._]]]] _f_i_l_e ... _----_llll_mmmm_aaaa_nnnn_gggg_llll_eeee _[[[[_l_i_b_r_a_r_y ..._]]]]
  15.  
  16.      _tttt_yyyy_pppp_eeee_dddd_eeee_ffff _ssss_tttt_rrrr_uuuu_cccc_tttt _DDDD_EEEE_MMMM_AAAA_RRRR_GGGG _DDDD_EEEE_MMMM_AAAA_RRRR_GGGG_;;;;
  17.      _tttt_yyyy_pppp_eeee_dddd_eeee_ffff _ssss_tttt_rrrr_uuuu_cccc_tttt _DDDD_EEEE_MMMM_CCCC_LLLL  _DDDD_EEEE_MMMM_CCCC_LLLL_;;;;
  18.      _tttt_yyyy_pppp_eeee_dddd_eeee_ffff _ssss_tttt_rrrr_uuuu_cccc_tttt _DDDD_EEEE_MMMM    _DDDD_EEEE_MMMM_;;;;
  19.  
  20.      _iiii_nnnn_tttt   _dddd_eeee_mmmm_aaaa_nnnn_gggg_llll_eeee_((((_cccc_oooo_nnnn_ssss_tttt _cccc_hhhh_aaaa_rrrr _****_iiii_nnnn_,,,, _cccc_hhhh_aaaa_rrrr _****_oooo_uuuu_tttt_))))_;;;;
  21.      _iiii_nnnn_tttt   _dddd_eeee_mmmm_((((_cccc_hhhh_aaaa_rrrr _****_ssss_,,,, _DDDD_EEEE_MMMM _****_pppp_,,,, _cccc_hhhh_aaaa_rrrr _****_bbbb_uuuu_ffff_))))_;;;;
  22.  
  23.      _vvvv_oooo_iiii_dddd  _dddd_eeee_mmmm______pppp_rrrr_iiii_nnnn_tttt_cccc_llll_((((_DDDD_EEEE_MMMM_CCCC_LLLL _****_pppp_,,,, _cccc_hhhh_aaaa_rrrr _****_bbbb_uuuu_ffff_))))_;;;;
  24.      _vvvv_oooo_iiii_dddd  _dddd_eeee_mmmm______pppp_rrrr_iiii_nnnn_tttt_aaaa_rrrr_gggg_((((_DDDD_EEEE_MMMM_AAAA_RRRR_GGGG _****_pppp_,,,, _cccc_hhhh_aaaa_rrrr _****_bbbb_uuuu_ffff_,,,, _iiii_nnnn_tttt _ffff_))))_;;;;
  25.      _vvvv_oooo_iiii_dddd  _dddd_eeee_mmmm______pppp_rrrr_iiii_nnnn_tttt_aaaa_rrrr_gggg_llll_iiii_ssss_tttt_((((_DDDD_EEEE_MMMM_AAAA_RRRR_GGGG _****_pppp_,,,, _cccc_hhhh_aaaa_rrrr _****_bbbb_uuuu_ffff_,,,, _iiii_nnnn_tttt _ssss_vvvv_))))_;;;;
  26.      _iiii_nnnn_tttt   _dddd_eeee_mmmm______pppp_rrrr_iiii_nnnn_tttt_((((_DDDD_EEEE_MMMM _****_pppp_,,,, _cccc_hhhh_aaaa_rrrr _****_bbbb_uuuu_ffff_))))_;;;;
  27.      _vvvv_oooo_iiii_dddd  _dddd_eeee_mmmm______pppp_rrrr_iiii_nnnn_tttt_ffff_uuuu_nnnn_cccc_((((_DDDD_EEEE_MMMM _****_dddd_pppp_,,,, _cccc_hhhh_aaaa_rrrr _****_bbbb_uuuu_ffff_))))_;;;;
  28.  
  29. DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  30.      _dddd_eeee_mmmm and _dddd_eeee_mmmm_aaaa_nnnn_gggg_llll_eeee are interfaces for user programs to ``demangle'' the
  31.      mangled external names that C++ produces for functions, class members,
  32.      etc..
  33.  
  34.      A description of the C++ mangling scheme is provided on page 122 and
  35.      following of the Annotated C++ Reference Manual.
  36.  
  37.  
  38.  
  39.      The simplest interface to the library is to call the ddddeeeemmmmaaaannnngggglllleeee(((()))) function,
  40.      as follows:
  41.  
  42.          int ret;
  43.          char inbuf[1024];
  44.          char outbuf[MAXDBUF];
  45.  
  46.          if ((ret = demangle(inbuf,  outbuf)) < 0) {
  47.              /* error! */
  48.          }
  49.  
  50.      The _dddd_eeee_mmmm_aaaa_nnnn_gggg_llll_eeee_((((_)))) function will return 0 if it successfully demangled the
  51.      name. If the demangle operation fails, the input string (inbuf) is copied
  52.      to the output buffer (outbuf).
  53.  
  54.      To attain a finer level of control over the demangling operation, call
  55.      the _dddd_eeee_mmmm_((((_)))) function as follows:
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.                                                                         PPPPaaaaggggeeee 1111
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. ddddeeeemmmmaaaannnngggglllleeee((((3333CCCC++++++++))))                                                  ddddeeeemmmmaaaannnngggglllleeee((((3333CCCC++++++++))))
  71.  
  72.  
  73.  
  74.          int ret;
  75.          char inbuf[1024];
  76.          DEM d;
  77.          char sbuf[MAXDBUF];
  78.  
  79.          ret = dem(inbuf, &d, sbuf);
  80.  
  81.      where inbuf is the input name, d the data structure that dem() fills up,
  82.      and sbuf is used as an internal buffer that the demangler uses to
  83.      allocate this data structure (d will contain pointers into sbuf).
  84.  
  85.      Note that the first parameter to dem() is of type char *, not const char
  86.      *:  a call to dem() may alter its input.
  87.  
  88.      There is a constant _MMMM_AAAA_XXXX_DDDD_BBBB_UUUU_FFFF defined in dem.h.  This is the maximum size
  89.      of buffer required for an unmangled name's data structure.
  90.  
  91.      dem() returns -1 on error, otherwise 0.
  92.  
  93.      The include file _<<<<_dddd_eeee_mmmm_...._hhhh_>>>> has comments describing each field in the data
  94.      structures.  The data structures are somewhat complicated by the need to
  95.      handle nested types and function arguments which themselves are function
  96.      pointers with their own arguments.
  97.  
  98.      To format this data structure in various ways, there are several
  99.      functions:
  100.  
  101.      _dddd_eeee_mmmm______pppp_rrrr_iiii_nnnn_tttt_((((_)))) formats a complete demangled name from the contents of the
  102.      DEM structure.  _dddd_eeee_mmmm______pppp_rrrr_iiii_nnnn_tttt_cccc_llll_((((_)))) formats just a class name.  _dddd_eeee_mmmm______pppp_rrrr_iiii_nnnn_tttt_ffff_uuuu_nnnn_cccc_((((_))))
  103.      format just a function name.  _dddd_eeee_mmmm______pppp_rrrr_iiii_nnnn_tttt_aaaa_rrrr_gggg_((((_)))) formats a single function
  104.      argument.  _dddd_eeee_mmmm______pppp_rrrr_iiii_nnnn_tttt_aaaa_rrrr_gggg_llll_iiii_ssss_tttt_((((_)))) formats a complete function argument list.
  105.  
  106.  
  107. DDDDIIIIAAAAGGGGNNNNOOOOSSSSTTTTIIIICCCCSSSS
  108.      _dddd_eeee_mmmm_aaaa_nnnn_gggg_llll_eeee_((((_)))), _dddd_eeee_mmmm_((((_)))) and _dddd_eeee_mmmm______pppp_rrrr_iiii_nnnn_tttt_((((_)))) return 0 if they succeed, and -1 if the
  109.      input name is not a valid mangled name (or if there are any other error
  110.      conditions, like passing in invalid arguments).
  111.  
  112.  
  113. EEEEXXXXAAAAMMMMPPPPLLLLEEEE
  114.      This particular application reads from standard input and displays the
  115.      class name for each mangled name read, or "(none)" on errors and C
  116.      functions/data.
  117.  
  118.          #include <stdio.h>
  119.          #include <dem.h>
  120.  
  121.          main()
  122.          {
  123.              char sbuf[MAXDBUF];
  124.              DEM d;
  125.              int ret;
  126.  
  127.  
  128.  
  129.                                                                         PPPPaaaaggggeeee 2222
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136. ddddeeeemmmmaaaannnngggglllleeee((((3333CCCC++++++++))))                                                  ddddeeeemmmmaaaannnngggglllleeee((((3333CCCC++++++++))))
  137.  
  138.  
  139.  
  140.              char buf[1024];
  141.              char buf2[1024];
  142.  
  143.              while (gets(buf) != NULL) {
  144.                  ret = dem(buf, &d, sbuf);
  145.                  if (ret || d.cl == NULL) {
  146.                      printf("%s --> (none)\n", buf);
  147.                  }
  148.                  else {
  149.                      dem_printcl(d.cl, buf2);
  150.                      printf("%s --> %s\n", buf, buf2);
  151.                  }
  152.              }
  153.          }
  154.  
  155.  
  156. TTTTYYYYPPPPEEEENNNNAAAAMMMMEEEESSSS
  157.      The demangler handles mangled class typenames, whether they are simple,
  158.      nested, or template classes.  For example:
  159.  
  160.          A__pt__2_i --> A<int>
  161.  
  162.          __Q2_1A1B --> A::B
  163.  
  164.  
  165.  
  166. LLLLOOOOCCCCAAAALLLL VVVVAAAARRRRIIIIAAAABBBBLLLLEEEESSSS
  167.      The demangler also handles local variables of the form:
  168.  
  169.          __nnnxxx
  170.  
  171.      For example:
  172.  
  173.          __2x --> x
  174.  
  175.  
  176. BBBBUUUUGGGGSSSS AAAANNNNDDDD AAAAMMMMBBBBIIIIGGGGUUUUIIIITTTTIIIIEEEESSSS
  177.      1.  "signed" and "volatile" encodings are not handled.
  178.  
  179.      2.  The encoding for nested classes as mentioned on page 123 of the ARM
  180.      is handled slightly differently in cfront;  there is a "_" after the
  181.      digit after the "Q".
  182.  
  183.      3.  A nested class starting with "Q" sometimes has the length encoded
  184.      before it;  the demangler handles either case.
  185.  
  186.      4.  The "Tnn" and "Nnnn" notations mentioned on page 124 are not fully
  187.      supported.  It is assumed that the number of the designated argument is
  188.      less than or equal to 9.  So if you have 11 or more arguments, and you
  189.      want to repeat argument 10 or greater, the demangler will reject the
  190.      encoded name.
  191.  
  192.  
  193.  
  194.  
  195.                                                                         PPPPaaaaggggeeee 3333
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202. ddddeeeemmmmaaaannnngggglllleeee((((3333CCCC++++++++))))                                                  ddddeeeemmmmaaaannnngggglllleeee((((3333CCCC++++++++))))
  203.  
  204.  
  205.  
  206.      5.  All literal arguments to templates are assumed to be const.  For
  207.      example, the non-const literal value "37" is encoded as "Ci".
  208.  
  209.      6.  Some compilers will add a gratuitous "_" before external names.
  210.  
  211.      7.  The grammar allows class names up to 999 characters.  This is
  212.      considered important for handling templates.
  213.  
  214.  
  215.  
  216. GGGGRRRRAAAAMMMMMMMMAAAARRRR FFFFOOOORRRR EEEEXXXXTTTTEEEERRRRNNNNAAAALLLL NNNNAAAAMMMMEEEESSSS
  217.      start       -->     name
  218.  
  219.      ################# COMPLETE NAMES #################
  220.  
  221.      name        -->     sti | std | ptbl | func | data | vtbl |
  222.                          cname3 | local
  223.      sti         -->     "__sti" "__" id
  224.      std         -->     "__std" "__" id
  225.      ptbl        -->     "__ptbl_vec" "__" id
  226.      func        -->     "__op" arg funcpost | id funcpost
  227.      funcpost    -->     "__" funcpost2 | "__" cname funcpost2
  228.      funcpost2   -->     csv "F" arglist
  229.      csv         -->     "" | "C" | "S" | "V"
  230.      data        -->     id | id "__" cname
  231.      vtbl        -->     "__vtbl" "__" cname
  232.      local       -->     "__" num regid
  233.  
  234.      ################# CLASS NAMES #################
  235.  
  236.      cname       -->     cname2 | nest
  237.      nest        -->     "Q" digit "_" cnamelist
  238.      cnamelist   -->     cname2 | cnamelist cname2
  239.      cname2      -->     cnlen cnid
  240.      cname3      -->     cnid | "__" nest
  241.      cnlen       -->     digit | digit digit | digit digit digit
  242.      cnid        -->     id | id "__pt__" cnlen "_" arglist
  243.  
  244.      ################# ARGUMENT LISTS #################
  245.  
  246.      arglist     -->     arg | arglist arg
  247.      arg         -->     modlist arg2 | "X" modlist arg2 lit
  248.      modlist     -->     mod | modlist mod
  249.      mod         -->     "" | "U" | "C" | "V" | "S" | "P" | "R" |
  250.                          arr | mptr
  251.      arr         -->     "A" num "_"
  252.      mptr        -->     "M" cname
  253.      arg2        -->     fund | cname | funcp | repeat1 | repeat2
  254.      fund        -->     "v" | "c" | "s" | "i" | "l" | "f" |
  255.                          "d" | "r" | "e"
  256.      funcp       -->     "F" arglist "_" arg
  257.      repeat1     -->     "T" digit | "T" digit digit
  258.  
  259.  
  260.  
  261.                                                                         PPPPaaaaggggeeee 4444
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268. ddddeeeemmmmaaaannnngggglllleeee((((3333CCCC++++++++))))                                                  ddddeeeemmmmaaaannnngggglllleeee((((3333CCCC++++++++))))
  269.  
  270.  
  271.  
  272.      repeat2     -->     "N" digit digit | "N" digit digit digit
  273.      lit         -->     litnum | zero | litmptr | cnlen id | sptr
  274.      litnum      -->     "L" digit lnum | "L" digit digit "_" lnum
  275.      litmptr     -->     "LM" num "_" litnum "_" cnlen id
  276.      lnum        -->     num | "n" num
  277.      sptr        -->     cnlen id "__" cname
  278.      zero        -->     0
  279.  
  280.      ################# LOW LEVEL STUFF #################
  281.  
  282.      digit       -->     0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
  283.      id          -->     special | regid
  284.      special     -->     "__ct" | "__pp" # etc.
  285.      regid       -->     letter | letter restid
  286.      restid      -->     letter | digit | restid letter |
  287.                          restid digit
  288.      letter      -->     "A"-"Z" | "a" - "z" | "_"
  289.      num         -->     digit | num digit
  290.  
  291.  
  292.  
  293.  
  294.  
  295.  
  296.  
  297.  
  298.  
  299.  
  300.  
  301.  
  302.  
  303.  
  304.  
  305.  
  306.  
  307.  
  308.  
  309.  
  310.  
  311.  
  312.  
  313.  
  314.  
  315.  
  316.  
  317.  
  318.  
  319.  
  320.  
  321.  
  322.  
  323.  
  324.  
  325.  
  326.  
  327.                                                                         PPPPaaaaggggeeee 5555
  328.  
  329.  
  330.  
  331.